clear 
set more off

use "Study_3_data.dta"

ssc install cibar
ssc install coefplot
ssc install estout, replace
ssc install orth_out
ssc install fre

factor aot_1 aot_2 aot_3 aot_4 aot_5
alpha aot_1 aot_2 aot_3 aot_4 aot_5
factor aot_3 aot_4 aot_5
gen aot_index=(aot_3+aot_4+aot_5)

factor consmentality_1 consmentality_2 consmentality_3 consmentality_4 consmentality_5
alpha consmentality_1 consmentality_2 consmentality_3 consmentality_4 consmentality_5
gen cm=(consmentality_1+consmentality_2+consmentality_3+consmentality_4+consmentality_5)

factor trust_parl trust_legal trust_pol trust_polit trust_party
alpha trust_parl trust_legal trust_pol trust_polit trust_party
gen poltrust=(trust_parl+trust_legal+trust_pol+trust_polit+trust_party)

tab trust_scien
/// something is happening with the variable trust_scient, so I create a copy variable to see if I could then standardize it properly. // yes, it worked. 

tab trust_scien
gen trustsci=trust_scien
tab trustsci


// standardizing the variables for ease in interpretation [0,1]

	foreach var in poltrust aot_index cm intertrust trustCA trustsci {
		qui sum `var'
		replace `var' = (`var' - `r(min)') / (`r(max)'-`r(min)')

	}

	foreach var in poltrust aot_index cm intertrust trustCA trustsci  {
tab `var' 
}

 

sum change_misp
tab change_misp

// wald test

reg change_misp i.treatment
test 2.treatment=3.treatment


/// to see what this effect mean in standardized terms, we standardize the change variable by the control condition´s mean and sd. 

sum change_misp if treatment==1
gen stanchange=(change_misp-.1547085)/.8510735

reg stanchange i.treatment
estimates store m1

reg stanchange i.treatment gender age_cat edu_Ireland ib(3).Race polideol i.partisan_Ireland trust_scien poltrust intertrust trustCA news_corona cm aot_index
estimates store m2

estout m1 m2, cells(b(star fmt(3)) se(par fmt(2)))  stats(r2)



********************************************************************************
**************************** ADDITIONAL TESTS***********************************
********************************************************************************

// Nyhan and Reifler Strategy

// rescaling the variables so that the greater numbers indicate more accurate beliefs.
fre mis_labmade
recode mis_labmade (1=5 "not accurate") (2=4 "probably not accurate") (3=3 "unsure") (4=2 "probably accurate") (5=1 "accurate"),gen(pre)
tab mis_labmade
tab pre


fre post_mis_labmade
recode post_mis_labmade (1=5 "not accurate") (2=4 "probably not accurate") (3=3 "unsure") (4=2 "probably accurate") (5=1 "accurate"),gen(post)
tab post_mis_labmade
tab post

****

reg post i.treatment pre
estimates store m1

// w/ covariates
reg post i.treatment pre gender age_cat edu_Ireland ib(3).Race polideol i.partisan_Ireland trust_scien poltrust intertrust trustCA news_corona cm aot_index
estimates store m2

estout m1 m2, cells(b(star fmt(3)) se(par fmt(2)))  stats(r2)

// Manipulation Check Question

tab manipulation_check
tab treatment   // control, expert and minipublic

gen compliance=.
replace compliance=1 if manipulation_check==3&treatment==1   //control
replace compliance=0 if manipulation_check==3&treatment!=1   //control

replace compliance=1 if manipulation_check==1&treatment==2	//expert
replace compliance=0 if manipulation_check==1&treatment!=2	//expert

replace compliance=1 if manipulation_check==2&treatment==3	//mini-public
replace compliance=0 if manipulation_check==2&treatment!=3	//mini-public

replace compliance=0 if manipulation_check==4

tab compliance
tab treatment

by treatment, sort : tabulate compliance
by treatment, sort: tabulate manipulation_check

reg change_misp i.treatment if compliance==1
estimates store m1
// w/ covariates
reg change_misp i.treatment gender age_cat edu_Ireland ib(3).Race polideol i.partisan_Ireland trust_scien poltrust intertrust trustCA news_corona cm aot_index if compliance==1
estimates store m2

estout m1 m2, cells(b(star fmt(3)) se(par fmt(2)))  stats(r2)

tab manipulation_check
by treatment, sort : tabulate manipulation_check

// Treating the "don´t know" as missing values, and deleting them list-wise and rerunning the analyses

fre mis_labmade
fre post_mis_labmade

recode mis_labmade (3=.) (4=3)(5=4),gen (m1)
tab mis_labmade
tab m1

recode post_mis_labmade (3=.) (4=3)(5=4),gen (m2)
fre post_mis_labmade
fre m2

gen changem=(m2-m1)
fre changem
recode changem (-3=3)(-2=2)(-1=1)(0=0)(1=-1)(2=-2)		//to make the positive coefficient to show correction

reg changem i.treatment
estimates store m1
// w/ covariates
reg changem i.treatment gender age_cat edu_Ireland ib(3).Race polideol i.partisan_Ireland trust_scien poltrust intertrust trustCA news_corona cm aot_index
estimates store m2
estout m1 m2, cells(b(star fmt(3)) se(par fmt(2)))  stats(r2)

///

fre polideol
recode polideol (0 1 2 3 4=1 "left")(5=2 "middle")(6 7 8 9 10=3 "right"),gen(catide)
tab catide

	foreach var in gender age_cat edu_Ireland Race partisan_Ireland catide {
tab `var' 
}

//// THE BALANCE TESTS ////

orth_out gender age_cat edu_Ireland Race partisan_Ireland catide, by(treatment) replace se compare test count


